package net.sunbeta.test.database ;

import java.sql.PreparedStatement ;
import java.sql.SQLException ;
import java.util.List ;

import org.springframework.jdbc.core.BatchPreparedStatementSetter ;
import org.springframework.jdbc.core.PreparedStatementSetter ;

abstract public class AbstractPreparedStatementSetter<T> implements PreparedStatementSetter, BatchPreparedStatementSetter {
    private List<T> objects ;

    protected AbstractPreparedStatementSetter(List<T> objects) {
        this.objects = objects ;
    }

    public void setValues(PreparedStatement preparedStatement) throws SQLException {
        fillStatement(objects.get(0), preparedStatement) ;
    }

    public void setValues(PreparedStatement preparedStatement, int i) throws SQLException {
        fillStatement(objects.get(i), preparedStatement) ;
    }

    public int getBatchSize() {
        return objects.size() ;
    }

    abstract public void fillStatement(T object, PreparedStatement statement) throws SQLException ;
}
